// 1： 导入路由
import {createRouter, createWebHistory} from 'vue-router'


//3: 创建路由器对象，将模板全部进行路由匹配和注册
const router = createRouter({
    // URL访问模式，http://localhost:8080/news
    history: createWebHistory(),
    routes: [
        // 设置欢迎页面，就path设置成 "/"即可
        {path: '/', name: "index", meta: {title: "首页"}, component: () => import("@/views/Home")},
        {path: '/news', name: "news", meta: {title: "新闻"}, component: () => import("@/views/News")},
        {path: '/course', name: "course", meta: {title: "课程"}, component: () => import("@/views/Course")},
        {path: '/video', name: "video", meta: {title: "视频"}, component: () => import("@/views/Video")},

        // 这个路由跳书籍页面(父子路由)
        // 子路由只能在父页面去找<router-view>，如果找不到就 终止渲染
        {
            path: '/book', name: "book", meta: {title: "图书"}, component: () => import("@/views/Book"), children: [
                {
                    path: '/book/:id',
                    name: "bookdetails1",
                    meta: {title: "书籍明细1"},
                    component: () => import("@/views/BookDetails")
                },
                {
                    path: '/book2',
                    name: "bookdetails2",
                    meta: {title: "书籍明细2"},
                    component: () => import("@/views/BookDetails")
                },
                {
                    path: '/bookdetail/:id/:title/:author',
                    name: "bookdetails3",
                    meta: {title: "书籍明细3"},
                    component: () => import("@/views/BookDetails2"),
                    props:true
                },
            ]
        },

        // 用户管理
        {
            path: '/user',
            name: "user",
            meta: {title: "用户管理"},
            component: () => import("@/views/user/UserMain"),
            children: [
                {path: '/user', name: "userlist", meta: {title: "用户列表"}, component: () => import("@/views/user/UseList")},
                {path: '/user/add', name: "useradd", meta: {title: "用户添加"}, components: {Add:() => import("@/views/user/UseAdd")}},
            ]
        },

        // 登录
        {path: '/login', name: "login", meta: {title: "登录"}, component: () => import("@/views/Login")},

    ]
})

router.afterEach(to => {
    document.title = to.meta.title;
})


// 4: 导出模板router模块即可
export default router